﻿

var chart;
google.load('visualization', '1', { packages: ['orgchart'] });
google.setOnLoadCallback(drawChart);

function drawChart() {
    var text = document.getElementById("departments").value; 

    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Name');
    data.addColumn('string', 'Manager');
    data.addColumn('string', 'ToolTip');
    data.addRows(eval(text));

    //function when user clicks on a node
    function selectHandler() { 
        var selectedItem = chart.getSelection()[0];
        if (selectedItem) {

            var partyRoleID = data.getValue(selectedItem.row, 0);

            $.post($('#editUrl').val() + '?partyRoleID=' + partyRoleID);
            //{
            //    window.location.reload(true);
            //};
            //$.post($('#editUrl').val(), { partyRoleID: partyRoleID) }, function(data) {
            //    //Do Something.
            //});

            ////alert('The user selected ' + partyRoleID);
            
        }
    }

    chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
    google.visualization.events.addListener(chart, 'select', selectHandler);
    
    

    
    chart.draw(data, { allowHtml: true });

}




